From ab148e863bf28d25689a25bbf863bcc7b9b8773b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 23 Jul 2014 12:49:32 -0700 Subject: [PATCH] Ensure a message is printed on test failure This previously relied on the test itself printing failure, but this is not always the case for test which, for example, segfault. Instead this ensures that *something* is always printed when a test fails, normally a short blurb about what executable failed to run. --- src/bin/cargo-test.rs | 11 +++++++++-- tests/test_cargo_test.rs | 7 ++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/bin/cargo-test.rs b/src/bin/cargo-test.rs index 707681ae6..1337b57b8 100644 --- a/src/bin/cargo-test.rs +++ b/src/bin/cargo-test.rs @@ -9,12 +9,13 @@ extern crate serialize; extern crate hammer; use std::os; +use std::io::process::ExitStatus; use cargo::ops; use cargo::{execute_main_without_stdin}; use cargo::core::{MultiShell}; use cargo::util; -use cargo::util::{CliResult, CliError, human}; +use cargo::util::{CliResult, CliError, CargoError}; use cargo::util::important_paths::find_project_manifest; #[deriving(PartialEq,Clone,Decodable)] @@ -62,7 +63,13 @@ fn execute(options: Options, shell: &mut MultiShell) -> CliResult> { for file in test_executables.iter() { try!(util::process(test_dir.join(file.as_slice())) .args(options.rest.as_slice()) - .exec().map_err(|_| CliError::from_boxed(human(""), 1))); + .exec().map_err(|e| { + let exit_status = match e.exit { + Some(ExitStatus(i)) => i as uint, + _ => 1, + }; + CliError::from_boxed(e.mark_human(), exit_status) + })); } Ok(None) diff --git a/tests/test_cargo_test.rs b/tests/test_cargo_test.rs index 1a0ff9c94..d32da323e 100644 --- a/tests/test_cargo_test.rs +++ b/tests/test_cargo_test.rs @@ -106,7 +106,12 @@ test!(cargo_test_failing_test { test result: FAILED. 0 passed; 1 failed; \ 0 ignored; 0 measured\n\n", COMPILING, p.root().display(), - sep = path::SEP))); + sep = path::SEP)) + .with_stderr(format!("\ +task '
' failed at 'Some tests failed', [..] +Could not execute process `{test}[..]` (status=101) +", test = p.root().join("target/test/foo").display())) + .with_status(101)); }) test!(test_with_lib_dep { -- 2.30.2